package com.hanamaki.databaseTest.util;

import com.mcha nge.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.*;


/**
 * 工具类
 */
public class JDBCUtil_C3P0 {

    static DataSource dataSource;
    static{
        dataSource = new ComboPooledDataSource("MySources");
    }


    public static Connection getCon() throws SQLException {
        return dataSource.getConnection();
    }

    public static void release(Connection connection, ResultSet resultSet, Statement statement, PreparedStatement preparedStatement) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }if (connection != null) {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }

    }
}
